import { createSlice, PayloadAction } from "@reduxjs/toolkit";

// import { handleData } from "../utils";
import { GlobalState } from "../interface";

const globalState: GlobalState = {
	token: "token init"
};

// 登录
// export const loginAction = createAsyncThunk(
// 	"global/login",
// 	async (params: LoginData, { dispatch }) => {
// 		const res = await handleData({ params, dispatch, apiFn: login, setDataFn: setLoginData });
// 		if (res?.payload?.token) {
// 			dispatch(userInfoAsync());
// 		}
// 	}
// );

const globalSlice = createSlice({
	name: "global",
	initialState: globalState,
	reducers: {
		setToken(state: GlobalState, { payload }: PayloadAction<string>) {
			state.token = payload;
		}
	}
});
export const { setToken } = globalSlice.actions;
export default globalSlice.reducer;
